package dw.fastfile.business.controller;

import dw.fastfile.business.dto.Dog;
import dw.fastfile.business.dto.DogClassExport;
import dw.fastfile.business.dto.DogDto;
import dw.fastfile.business.dto.DogQuery;
import dw.fastfile.business.service.DogPageService;
import dw.fastfile.business.service.DogService;
import dw.fastfile.common.dto.CommonResponse;
import dw.fastfile.common.dto.PageRequest;
import dw.fastfile.common.dto.PageResponse;
import dw.fastfile.common.exception.BusinessException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @description:
 * @author: wanghao
 * @create: 2022-11-30 17:23
 **/
@RequestMapping("dog")
@RestController
public class DogCtrl {
    @Resource
    private DogPageService dogPageService;

    @Resource
    private DogService dogService;

    @PostMapping(value = "page")
    public CommonResponse<PageResponse<Dog>> page(@RequestBody PageRequest<DogQuery> request) {
        PageResponse<Dog> dogPageResponse = dogPageService.queryByPage(request);

        return CommonResponse.success(dogPageResponse);
    }

    @PostMapping(value = "list")
    public CommonResponse<List<Dog>> page(@RequestBody DogQuery request) {
        return CommonResponse.success(dogPageService.queryNoPage(request));
    }

    @PostMapping(value = "save")
    public CommonResponse<DogDto> save(@RequestBody @Valid DogDto dogDto) {
        dogService.save(dogDto);
        return CommonResponse.success(dogDto);
    }

    @GetMapping(value = "testException")
    public String test() {
        throw new BusinessException("test");
    }

    @GetMapping(value = "testTransform")
    public CommonResponse<DogClassExport> testTransform() {
        return CommonResponse.success(dogService.testTransform());
    }
}
